package cn.vcjf.washcar.api.service.controller;


import cn.vcjf.washcar.api.service.entity.CarBrand;
import cn.vcjf.washcar.api.service.service.CarBrandService;
import cn.vcjf.washcar.common.web.TableResult;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * <p>
 * 汽车品牌表 前端控制器
 * </p>
 *
 * @author zhengzihang
 * @since 2018-07-20
 */
@Controller
@RequestMapping("/service/carBrand")
public class CarBrandController {
     @Resource
     private CarBrandService  carBrandService;

     @RequestMapping("/addCarBrand")
     @ResponseBody
     public TableResult addCarBrand(CarBrand carBrand){
         carBrand.preInsert();
         boolean b = carBrandService.insert(carBrand);
         return TableResult.Result(b);
     }

     @RequestMapping("/updateCarBrand")
     @ResponseBody
     public TableResult updateCarBrand(CarBrand carBrand){
         carBrand.preUpdate();
        boolean b = carBrandService.updateById(carBrand);
         return TableResult.Result(b);
     }

     @RequestMapping("/findCarBrandOne")
     @ResponseBody
     public TableResult findCarBrandOne(CarBrand carBrand){

        EntityWrapper<CarBrand> wrapper = new EntityWrapper<CarBrand>();

        if(carBrand.getId()!=null){
            wrapper.eq("id",carBrand.getId());
        }
        //Todo

        CarBrand result = carBrandService.selectOne(wrapper);

		return TableResult.Result(result);
     }

     @RequestMapping("/findCarBrandList")
     @ResponseBody
     public TableResult findCarBrandList(CarBrand carBrand){

        EntityWrapper<CarBrand> wrapper = new EntityWrapper<CarBrand>();

		if(carBrand.getId()!=null){
            wrapper.eq("id",carBrand.getId());
        }
        //Todo

        Page<CarBrand> page = new Page<CarBrand>(carBrand.getPage(), carBrand.getLimit());

        Page<CarBrand> result = carBrandService.selectPage(page,wrapper);

		return TableResult.Result(result);

     }

     @RequestMapping("/deleteCarBrand")
     @ResponseBody
     public TableResult deleteCarBrand(CarBrand carBrand){
        carBrand.preUpdate();
        boolean b = carBrandService.deleteById(carBrand.getId());
        return TableResult.Result(b);
     }

}
